import { USER_LOGIN , INIT_USER , LOGIN_OUT} from './mutations-types'
export default{
    state:{
        loginStatus:false,//登入的状态
        token:null,//token
        userInfo:{},//用户信息:用户的头像|用户昵称

    },
    getters:{

    },
    mutations:{
        //设置
        [USER_LOGIN]( state,user){
            state.loginStatus = true,
            state.token = user.token,
            state.userInfo = user;
            //持久化存储=》本地存储
            localStorage.setItem('teaUserInfo',JSON.stringify(user))
        },
        //读取
        [INIT_USER]( state ){
            let userInfo = JSON.parse( localStorage.getItem('teaUserInfo'))
            if( userInfo){
                state.loginStatus = true;
                state.token = userInfo.token;
                state.userInfo = userInfo;
            }
            // state.token = userObj.token;//存储用户token了
            // state.userInfo = userObj;//存储用户信息了
            // state.userStatus = true;//登录了
            //存到本地存储
        },
        //退出登录
        loginOut(state){
            state.loginStatus = false,
            state.token = null,
            state.userInfo = {},
            localStorage.removeItem('teaUserInfo')
        },
    },
    actions:{

    }
}